<?php
namespace Controller;

use Hoa\Registry\Registry;
use Library\View;
use Logic\CardLogic;
use Service\CardService;


/**
 * Card
 * @author los_gsy
 */
class CardController extends BaseController {
	/**
	 * 构造函数
	 */
	public function __construct() {
		parent::__construct();
	}


	/**
	 * test
	 */
	public function test() {
		//echo __METHOD__;
		//$result = CardLogic::cacheNewCardCodeList();
		$result = CardService::placeOrder();
		var_dump($result);
	}


	/**
	 * 下单
	 */
	public function placeOrder() {
		$data = [];
		$data['cardCnt'] = CardLogic::getNewCardCnt();
		View::display('Card/placeOrder', $data);
	}


	/**
	 * do下单
	 * 目前只支持购买一张卡
	 */
	public function doPlaceOrder() {
		//定义变量
		$conf = Registry::get('conf');
		$ret = $conf['status'][200];

		//下单
		$cardCode = CardService::placeOrder();
		if (!$cardCode) {
			$ret = $conf['status'][40010101];
			exit(json_encode($ret));
		}

		//Success
		$ret['cardCode'] = $cardCode;
		echo json_encode($ret);
	}


	/**
	 * do下单，成功
	 */
	public function doPlaceOrderSuccess() {
		//获取参数
		$cardCode = I('get.cardCode');

		//Success
		$data = [];
		$data['cardCode'] = $cardCode;
		View::display('Card/doPlaceOrderSuccess', $data);
	}



}
